package com.ayou.eggguard.farm.mapper;

import com.ayou.eggguard.farm.pojo.Case;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface CaseMapper {
    List<Case> getCases(String caseNumber);

    @Insert("insert into `case`(coop_number, column_number, storey_number, cage_number, action, feature, check_result, diagnose_result, cheat_method, cheat_result, case_number) " +
            "values(#{coopNumber},#{columnNumber},#{storeyNumber},#{cageNumber},#{action},#{feature},#{checkResult},#{diagnoseResult},#{cheatMethod},#{cheatResult},#{caseNumber})")
    void add(Case c);

    @Update("update `case` set coop_number=#{coopNumber},column_number=#{columnNumber},storey_number=#{storeyNumber}," +
            "cage_number=#{cageNumber},action=#{action},feature=#{feature},check_result=#{checkResult},diagnose_result=#{diagnoseResult}," +
            "cheat_method=#{cheatMethod},cheat_result=#{cheatResult},case_number=#{caseNumber} where id=#{id}")
    void update(Case c);

    @Delete("delete from `case` where id=#{id}")
    void delete(Integer id);

    @Select("select `case`.coop_number,count(*) as frequency from `case` group by coop_number")
    List<Map<String, Object>> getCaseFrequency();

    @Select("select `case`.cheat_method as name,count(*) as value from `case` group by cheat_method")
    List<Map<String, Object>> getBlightCount();
}
